package com.greenhou.dao.impl;

import com.greenhou.dao.UserDao;
import com.greenhou.io.Resources;
import com.greenhou.pojo.User;
import com.greenhou.sqlSession.SqlSession;
import com.greenhou.sqlSession.SqlSessionFactory;
import com.greenhou.sqlSession.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

/**
 * @ClassName UserDaoImpl
 * @Description 用户Dao实现
 * @Author YR
 * @Date 2020/7/6 22:41
 * @Version 1.0
 */
public class UserDaoImpl implements UserDao {
    public List<User> queryUserList() throws Exception {
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = build.openSession();

        List<User> userList=sqlSession.selectList("com.greenhou.mapper.UserMapper.selectList");
        return userList;
    }

    public User queryUserByCondition(User user) throws Exception {
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = build.openSession();

//        User puser=new User();
//        puser.setUsername("tom");
        User dbUser=sqlSession.selectOne("com.greenhou.mapper.UserMapper.selectOne",user);
        return dbUser;
    }
}
